require 'fileutils'

module MassiveClassRoom
  class CLI
    DIRS = ['students', 'quests']
    def self.parse! argv
      @command = argv.shift
      case @command
      when 'init', 'initialize', 'new'
        target = argv.shift
        create_directories target
      when 'help'
        puts "Usage: mcr [init, initialize, new] <target directory>"
      end
    end


    private

    def self.create_directories target
      begin
        FileUtils.mkdir target
        puts "  Directory: #{target} created."
        DIRS.each do |subdir|
          dir = FileUtils.mkdir "#{target}/#{subdir}"
          puts "  Directory #{dir.join} created."
        end
        exit(true)
      rescue Errno::EEXIST
        puts "Aborting: Directory #{target} exists!"
        exit(false)
      end
    end
  end
end
